﻿using System;
using System.Collections;

namespace YArchitech.HCLoad.XmlData
{
	public class RoomLoadCollect : Hashtable
	{
		public RoomLoadCollect(Room room)
		{
			this.parent = room;
		}

		public Room Parent
		{
			get
			{
				return this.parent;
			}
			set
			{
				this.parent = value;
			}
		}

		public DataBase DataBase
		{
			get
			{
				return this.Parent.DataBase;
			}
		}

		public int AddRoomLoad(RoomLoad roomLoad)
		{
			int result;
			try
			{
				roomLoad.ParentRoomLoadCollect = this;
				int num = this.DataBase.AddCurrID();
				roomLoad.ID = num;
				this.Add(num, roomLoad);
				this.DataBase.hCurrIDList.Add(num, roomLoad);
				result = num;
			}
			catch (Exception ex)
			{
				throw new Exception(ex.ToString());
			}
			return result;
		}

		public void RemoveRoomLoad(int ID)
		{
			try
			{
				this.Remove(ID);
				this.DataBase.hCurrIDList.Remove(ID);
			}
			catch (Exception ex)
			{
				throw new Exception(ex.ToString());
			}
		}

		public RoomLoad GetRoomLoad(int ID)
		{
			RoomLoad result;
			try
			{
				result = (RoomLoad)this[ID];
			}
			catch (Exception ex)
			{
				throw new Exception(ex.ToString());
			}
			return result;
		}

		public bool LoadRoomLoad(RoomLoad roomLoad)
		{
			bool result;
			try
			{
				roomLoad.ParentRoomLoadCollect = this;
				int id = roomLoad.ID;
				if (this.DataBase.hCurrIDList.ContainsKey(id))
				{
					result = false;
				}
				else
				{
					if (id > this.DataBase.CurrID)
					{
						this.DataBase.CurrID = id;
					}
					this.Add(id, roomLoad);
					this.DataBase.hCurrIDList.Add(id, roomLoad);
					result = true;
				}
			}
			catch (Exception ex)
			{
				throw new Exception(ex.ToString());
			}
			return result;
		}

		private Room parent;
	}
}
